<?php

namespace App\Remote\HonorPush;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class HonorPushRemote extends Remote
{

    /**
     * @param array $tokens
     * @param string $title
     * @param string $body
     * @param string $path
     * @param array $extra
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function tokensMultiPush(array $tokens, string $title, string $body, string $path, array $extra = [])
    {
        $appId = config("push.honor.appId");
        return self::customRequestV3(
            "api/v1/{$appId}/sendMessage",
            RequestAlias::METHOD_POST,
            [
                "notification" => [
                    "title" => $title,
                    "body"  => $body
                ],
                "android"      => [
                    "data"         => json_encode([
                        "kf" => array_merge(["path" => $path], $extra)
                    ], JSON_UNESCAPED_UNICODE),
                    "notification" => [
                        "importance"  => "NORMAL",
                        "clickAction" => ["type" => 3]
                    ]
                ],
                "token"        => $tokens
            ]
        );
    }
}
